﻿#include "ssProcessInfo.h"
#include "../file/ssPath.h"
#ifdef _WIN32
#include <windows.h>
#include <process.h>
#else
#include <unistd.h>
#include <string.h>
#endif


namespace StarSeeker
{

ssProcessInfo::ssProcessInfo()
{
	m_id = 0;
	GetInfo();
}

void ssProcessInfo::GetInfo()
{
	char szFileFullPath[1024] = {0};
#ifdef _WIN32
	::GetModuleFileNameA(NULL, static_cast<LPSTR>(szFileFullPath), 1024);
#else
	readlink("/proc/self/exe", szFileFullPath, 1024);
#endif
	m_fullPath = szFileFullPath;
	m_path = ssPath::RemoveFileName(szFileFullPath);
	m_name = ssPath::BaseName(szFileFullPath);

#ifdef _WIN32
	m_id = ::_getpid();
#else
	m_id = ::getpid();
#endif
#ifdef SS_USE_ANDROID
	m_resPath = "assets/";
#else
	m_resPath = "../res/";
#endif
}

std::string ssProcessInfo::GetResPath( const char* filename )
{
	std::string ret;
	if (filename && m_resPath.length()>0)
	{
		ret = m_resPath + filename;
	}
	return ret;
}

std::string ssProcessInfo::GetNameRemoveExt()
{
	return ssPath::RemoveExtName(m_name.c_str());
}

}
